package com.goktech.sportsmall.service.Impl;

import com.goktech.sportsmall.bean.CommSortBean;
import com.goktech.sportsmall.bean.ShoppingCartBean;
import com.goktech.sportsmall.mapper.ShoppingCartMapper;
import com.goktech.sportsmall.service.ShoppingCartService;
import com.goktech.sportsmall.utils.DateUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ShoppingCartServiceImpl implements ShoppingCartService {
    @Autowired(required = false)
    ShoppingCartMapper shoppingCartMapper;
    // 添加商品到购物车
    @Override
    public Map<String, Object> insertShoppingCart(ShoppingCartBean shoppingCartBean) {
        int cart = shoppingCartMapper.insertShoppingCart(shoppingCartBean);
        Map<String,Object> hashMap = new HashMap<>();
        hashMap.put("title","购物车添加信息");
        hashMap.put("time", DateUtil.getDate("yyyy/MM/dd HH:mm:ss"));
        if (cart == 1){
            hashMap.put("data",shoppingCartBean);
            hashMap.put("message","添加成功");
            return hashMap;
        }
        hashMap.put("data",shoppingCartBean);
        hashMap.put("message","添加失败");
        return hashMap;
    }


    // 查询用户对应的购物车商品
    @Override
    public Map<String, Object> selectByUId(String uId) {
        List<CommSortBean> beans = shoppingCartMapper.selectByUId(uId);
        Map<String,Object> hashMap = new HashMap<>();
        hashMap.put("title","查询购物车信息");
        hashMap.put("time", DateUtil.getDate("yyyy/MM/dd HH:mm:ss"));
        if (beans != null){
            hashMap.put("data",beans);
            hashMap.put("message","查询成功");
            return hashMap;
        }
        hashMap.put("data",uId);
        hashMap.put("message","查询失败");
        return hashMap;
    }

    // 删除商品
    @Override
    public Map<String, Object> deleteByNo(int scId) {
        int byNo = shoppingCartMapper.deleteByNo(scId);
        Map<String,Object> hashMap = new HashMap<>();
        hashMap.put("title","删除购物车信息");
        hashMap.put("time", DateUtil.getDate("yyyy/MM/dd HH:mm:ss"));
        if (byNo ==1){
            hashMap.put("data",scId);
            hashMap.put("message","删除成功");
            return hashMap;
        }
        hashMap.put("data",scId);
        hashMap.put("message","删除失败");
        return hashMap;
    }

    @Override
    public Map<String, Object> updateComm(ShoppingCartBean shoppingCartBean) {
        return null;
    }


}
